<?php
class Product extends CI_Model {

	private $data = array(
		'product' => array(),
		'total' => 0
    );
    
        
	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    

	
	public function getProduct ($listproductid)
	{
		$productid = implode(",", $listproductid);		
		$sql = sprintf("SELECT * FROM product where ProductId in (%s)",
		 mysql_real_escape_string($productid));
    
		$query = $this->db->query($sql);
		if ($query->num_rows() > 0) {
			foreach ($query->result() as $product_info) {
				$this->data['product'][$product_info->ProductId]['name'] = $product_info->Name;
				$this->data['product'][$product_info->ProductId]['quality'] = $product_info->Quatity;
				$this->data['product'][$product_info->ProductId]['price'] = $product_info->Price; 
				$this->data['product'][$product_info->ProductId]['url'] = $product_info->Url;                      
                $this->data['total']++;
			}
			return $this->data;
		} else {
			return null;
		}
	}
	
	public function getAllProduct ($listproductid)
	{
		$productid = implode(",", $listproductid);		
		$sql = sprintf("SELECT * FROM product where ProductId",
		 mysql_real_escape_string($productid));
    
		$query = $this->db->query($sql);
		if ($query->num_rows() > 0) {
			foreach ($query->result() as $product_info) {
				$this->data['product'][$product_info->ProductId]['name'] = $product_info->Name;
				$this->data['product'][$product_info->ProductId]['quality'] = $product_info->Quatity;
				$this->data['product'][$product_info->ProductId]['price'] = $product_info->Price; 
				$this->data['product'][$product_info->ProductId]['url'] = $product_info->Url;                      
                $this->data['total']++;
			}
			return $this->data;
		} else {
			return null;
		}
	}
	
	public function insertProduct($datainsert){
		$this->db->trans_begin();
		$this->db->insert('product', $datainsert); 
		
		if ($this->db->trans_status() === FALSE){
		    $this->db->trans_rollback();
		} else {
		    $this->db->trans_commit();
		}
	}
}
?>
